﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;


using P2PLib.Client.Command;
using P2PLib.Common.DataModel;
using P2PLib.Client.DataModel;

namespace P2PLib.Client
{
    //defines the event that occurs on client side

    /// <summary>
    /// contains the information about the server
    /// </summary>
    public class ServerEventArgs : EventArgs
    {
        private Socket socket;

        public IPAddress IP
        {
            get { return ((IPEndPoint)socket.RemoteEndPoint).Address; }
        }

        public int Port
        {
            get { return ((IPEndPoint)socket.RemoteEndPoint).Port; }
        }

        /// <summary>
        /// Create an instance of ServerEventArgs class
        /// </summary>
        /// <param name="socket">the clientsocket of the client that current connected to the server</param>
        public ServerEventArgs(Socket socket)
        {
            this.socket = socket;
        }
    }


    /// <summary>
    /// ocuurs when a client connected to a server
    /// </summary>
    /// <param name="sender">Sender</param>
    /// <param name="e">information abut the server</param>
    public delegate void ConnectingServerSucceedEventHandler(object sender, ServerEventArgs e);

    /// <summary>
    /// occurs when a client connect to a server failed
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void ConnectingServerFailedEventHandler(object sender,ServerEventArgs e);

    
    public class SearchEventArgs:EventArgs
    {
        private SearchType type;
        private string key;

        public SearchType Type
        {
            set
            {
                this.type=value;
            }
            get
            {
                return this.type;
            }
        }

        public string Key
        {
            set
            {
                this.key=value;
            }
            get
            {
                return this.key;
            }
        }

        public SearchEventArgs(SearchType t,string k)
        {
            this.type=t;
            this.key=k;
        }
    }
    /// <summary>
    /// DownloadTaskViewModel搜索时调用的方法
    /// </summary>
    public delegate void SearchEventHandler(object sender,SearchEventArgs e);


    public class ClientEventArgs : EventArgs
    {
        private ClientInfo client;

        public ClientInfo Client
        {
            set
            {
                this.client = value;
            }
            get
            {
                return this.client;
            }
        }

        public ClientEventArgs(ClientInfo cli)
        {
            this.client = cli;
        }
    }

    public delegate void ClientDisconnectedEventHandler(object sender,ClientEventArgs e);


    public class RequesFileEventArgs : EventArgs
    {
        private string fileHashCode;

        public string FileHashCode
        {
            set
            {
                this.fileHashCode = value;
            }
            get
            {
                return this.fileHashCode;
            }
        }

        public RequesFileEventArgs(string hashCode)
        {
            this.fileHashCode = hashCode;
        }
    }

    public delegate LocalFileInfo RequestFileEventHandler(object sender, RequesFileEventArgs e);

    /// <summary>
    /// occurs when client send a FileStartPosition command to request downloading
    /// return the current poistion of the client in the download queue
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <returns></returns>
    public delegate int RequestCurrentPositionEventHandler(object sender,ClientEventArgs e);


    public class SendingFileEventArgs : EventArgs
    {
        private long startPosition;

        public long StartPosition
        {
            get
            {
                return this.startPosition;
            }
            set
            {
                this.startPosition = value; ;
            }
        }

        public SendingFileEventArgs(long pos)
        {
            this.startPosition = pos;
        }
    }
    /// <summary>
    /// occurs when a client is able to downloading 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    public delegate void StartSendingEventHandler(object sender,SendingFileEventArgs e);


    
}
